package pl.enigmatic.test;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public abstract class Action implements ActionListener {

	private final String text;

	public Action(final String text) {
		this.text = text;
	}

	public Action() {
		this(null);
	}

	@Override
	public final void actionPerformed(final ActionEvent e) {
		final Object src = e.getSource();
		if (src instanceof Button) {
			onClick(((Button) src).getIndex());
		}
	}

	protected abstract void onClick(int index);

	public String getText() {
		return text;
	}
}